const readline = require('readline')
/** 读取命令行输入 */
const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout,
})
/** 移动 */
function* move(
    /** 环 */ annulus,
    /** 从这个柱移动 */ from,
    /** 中间柱 */ middle,
    /** 移动到这个柱 */ to
) {
    const msg = `环 ${annulus} from 柱 ${from} to 柱 ${to}`
    if (annulus === 1) {
        yield msg
    } else {
        yield* move(annulus - 1, from, to, middle)
        yield msg
        yield* move(annulus - 1, middle, from, to)
    }
}
/** 获得生成器 */
let g = move(3, 'A', 'C', 'B')
/** 同步执行 */
function syncWrite(msg) {
    return new Promise((resolve, reject) => {
        rl.question(`press [Enter] to continue...`, () => {
            resolve(msg)
        })
    })
}
/** 开始执行 */
async function start() {
    let step = 0
    for (const msg of g) {
        step++
        console.log(await syncWrite(msg + '\r\n'))
    }
    console.log(`total move [${step}] steps.`)
    process.exit(1)
}
start()
